package com.lizhangjun.nim.listener;

import com.lizhangjun.nim.constant.IMessage;
import com.lizhangjun.nim.constant.ImConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RocketMQMessageListener(topic = ImConstant.TOPIC_IM, consumerGroup = ImConstant.GROUP_DEFAULT)
public class RocketMQMsgListener implements RocketMQListener<IMessage> {

    @Autowired
    private Sender sender;

    @Value("${im.listener.rocketmq.isEnable}")
    private boolean enableRocketMq;

    @Override
    public void onMessage(IMessage iMessage) {
        //推送
        if (enableRocketMq){
            sender.send(iMessage);
        }
    }
}
